package me.zhao.proxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TimeHandler implements InvocationHandler{
	
	private Object target;
	public TimeHandler(Object target) {
		super();
		this.target = target;
	}
	
	/**
	 * 参数：
	 * proxy :被代理对象
	 * method：被代理对象方法
	 * args：方法参数
	 * 返回值：方法的返回值
	 */
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		long starttime = System.currentTimeMillis();
		System.out.println("汽车开始行驶...");
		method.invoke(target, null);
		long endtime = System.currentTimeMillis();
		System.out.println("汽车结束行驶...行驶时间：" + (endtime-starttime));
		
		return null;
	}

}
